package java44th.group.controller.admin.stat;

import java44th.group.bean.admin.vo.BaseRespVo;
import java44th.group.bean.admin.vo.stat.goods.GoodsVo;
import java44th.group.bean.admin.vo.stat.order.OrderVo;
import java44th.group.bean.admin.vo.stat.user.RowsEntity;
import java44th.group.bean.admin.vo.stat.user.UserVo;
import java44th.group.service.admin.stat.StatService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName project-second
 * @Descriptiom TODO
 * @Aurhor: 蔡文强
 * @Since: 2022/10/12 22:46
 */
@RestController
@RequestMapping("admin/stat")
public class StatController {

    @Autowired
    StatService statService;
    @RequiresPermissions("*")
    @RequestMapping(value = "user",method = RequestMethod.GET)
    public BaseRespVo user() {

        UserVo userVo = new UserVo();

        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("users");
        userVo.setColumns(columns);

        List<RowsEntity> rowsEntityList = statService.queryUserList();
        userVo.setRows(rowsEntityList);

        return BaseRespVo.ok(userVo);
    }
    @RequiresPermissions("*")
    @RequestMapping(value = "order",method = RequestMethod.GET)
    public BaseRespVo order() {
        OrderVo orderVo = new OrderVo();

        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("customers");
        columns.add("amount");
        columns.add("pcr");
        orderVo.setColumns(columns);

        List<java44th.group.bean.admin.vo.stat.order.RowsEntity> rowsEntityList = statService.queryOrderList();
        orderVo.setRows(rowsEntityList);

        return BaseRespVo.ok(orderVo);
    }
    @RequiresPermissions("*")
    @RequestMapping(value = "goods",method = RequestMethod.GET)
    public BaseRespVo goods() {

        GoodsVo goodsVo = new GoodsVo();

        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("products");
        columns.add("amount");
        goodsVo.setColumns(columns);

        List<java44th.group.bean.admin.vo.stat.goods.RowsEntity> rowsEntityList = statService.queryGoodsList();
        goodsVo.setRows(rowsEntityList);

        return BaseRespVo.ok(goodsVo);
    }

}
